package com.asset.dispoal.role;

import com.asset.dispoal.role.api.GbRoleService;
import com.asset.dispoal.role.dto.GbRoleRequest;
import com.asset.dispoal.role.dto.GbRoleResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.controller.BaseController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

/**
 * 角色表控制层
 *
 * @author: mhuang
 * @date: 2022-03-01 15:30:18
 */
@RestController
@Api(value = "角色管理", tags = "角色管理")
@RequestMapping("sys/gbRole")
public class GbRoleController extends BaseController {

    @Autowired
    GbRoleService gbRoleService;

    @Permission(code = "systemRole:query", param = "create_user_id")
    @GetMapping(value = "/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<PageVO<GbRoleResponse>> page(GbRoleRequest request) {
        return gbRoleService.queryPage(request);
    }

    @Permission(code = "systemRole:add")
    @PostMapping(value = "/insert")
    @ApiOperation(value = "添加", notes = "添加")
    public Result insert(@RequestBody GbRoleRequest request) {
        gbRoleService.insert(request);
        return Result.ok();
    }

    @Permission(code = "systemRole:update")
    @PutMapping(value = "/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result update(@RequestBody GbRoleRequest request) {
        gbRoleService.update(request);
        return Result.ok();
    }

    @Permission(code = "systemRole:del")
    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result delete(@RequestBody String id) {
        gbRoleService.delete(id);
        return Result.ok();
    }
}